package com.jjvu.news.service.impl;

import com.jjvu.news.dao.Info;
import com.jjvu.news.dao.MaxMenu;
import com.jjvu.news.dao.MinMenu;
import com.jjvu.news.domain.MenuDao;
import com.jjvu.news.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;
    public List<MaxMenu> findMaxMenuAll() {
        return menuDao.findMaxMenuAll();
    }

    public MaxMenu findMaxMenuById(Integer max_id) {
        MaxMenu maxMenu=new MaxMenu();
        maxMenu.setMax_id(max_id);
        return menuDao.findMaxMenuBy(maxMenu);
    }

    public boolean updateMaxMenu(MaxMenu maxMenu) {
        return menuDao.updateMaxMenu(maxMenu);
    }

    public boolean deleteMaxMenu(Integer max_id) {
        List<Info> infoByMaxId = menuDao.findInfoByMaxId(max_id);
        List<MinMenu> minMenuByMaxId = menuDao.findMinMenuByMaxId(max_id);
        if (infoByMaxId!=null&&minMenuByMaxId!=null){
            menuDao.deleteInfoByMaxId(max_id);
            menuDao.deleteMinMenuByMaxId(max_id);
            return menuDao.deleteMaxMenu(max_id);
        }else {
            return menuDao.deleteMaxMenu(max_id);
        }
    }

    public boolean addMaxMenu(MaxMenu maxMenu) {
        return menuDao.addMaxMenu(maxMenu);
    }

    public List<MaxMenu> findMinMenuByMaxName(Integer max_id) {
        return menuDao.findMinMenuByMaxName(max_id);
    }

    public MinMenu findMinMenuById(Integer min_id) {
        return menuDao.findMinMenuById(min_id);
    }

    public boolean updateMinMenu(MinMenu minMenu) {
        return menuDao.updateMinMenu(minMenu);
    }

    public boolean deleteMinMenu(Integer min_id) {
        List<Info> infoByMinId = menuDao.findInfoByMinId(min_id);
        if (infoByMinId!=null){
            menuDao.deleteInfoByMinId(min_id);
           return menuDao.deleteMinMenu(min_id);

        }else {
            return menuDao.deleteMinMenu(min_id);
        }
    }

    public boolean addMinMenu(MinMenu minMenu) {
        return menuDao.addMinMenu(minMenu);
    }

}
